\(\int \frac {1+x^2}{1+x+x^2} \, dx\) [168]

   Optimal result
   Rubi [A] (verified)
   Mathematica [A] (verified)
   Maple [A] (verified)
   Fricas [A] (verification not implemented)
   Sympy [A] (verification not implemented)
   Maxima [A] (verification not implemented)
   Giac [A] (verification not implemented)
   Mupad [B] (verification not implemented)

Optimal result

Integrand size = 14, antiderivative size = 31 \[ \int \frac {1+x^2}{1+x+x^2} \, dx=x+\frac {\arctan \left (\frac {1+2 x}{\sqrt {3}}\right )}{\sqrt {3}}-\frac {1}{2} \log \left (1+x+x^2\right ) \]

[Out]

x-1/2*ln(x^2+x+1)+1/3*arctan(1/3*(1+2*x)*3^(1/2))*3^(1/2)

Rubi [A] (verified)

Time = 0.02 (sec) , antiderivative size = 31, normalized size of antiderivative = 1.00, number of steps used = 6, number of rules used = 5, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.357, Rules used = {1671, 648, 632, 210, 642} \[ \int \frac {1+x^2}{1+x+x^2} \, dx=\frac {\arctan \left (\frac {2 x+1}{\sqrt {3}}\right )}{\sqrt {3}}-\frac {1}{2} \log \left (x^2+x+1\right )+x \]

[In]

Int[(1 + x^2)/(1 + x + x^2),x]

[Out]

x + ArcTan[(1 + 2*x)/Sqrt[3]]/Sqrt[3] - Log[1 + x + x^2]/2

Rule 210

Int[((a_) + (b_.)*(x_)^2)^(-1), x_Symbol] :> Simp[(-(Rt[-a, 2]*Rt[-b, 2])^(-1))*ArcTan[Rt[-b, 2]*(x/Rt[-a, 2])
], x] /; FreeQ[{a, b}, x] && PosQ[a/b] && (LtQ[a, 0] || LtQ[b, 0])

Rule 632

Int[((a_.) + (b_.)*(x_) + (c_.)*(x_)^2)^(-1), x_Symbol] :> Dist[-2, Subst[Int[1/Simp[b^2 - 4*a*c - x^2, x], x]
, x, b + 2*c*x], x] /; FreeQ[{a, b, c}, x] && NeQ[b^2 - 4*a*c, 0]

Rule 642

Int[((d_) + (e_.)*(x_))/((a_.) + (b_.)*(x_) + (c_.)*(x_)^2), x_Symbol] :> Simp[d*(Log[RemoveContent[a + b*x +
c*x^2, x]]/b), x] /; FreeQ[{a, b, c, d, e}, x] && EqQ[2*c*d - b*e, 0]

Rule 648

Int[((d_.) + (e_.)*(x_))/((a_) + (b_.)*(x_) + (c_.)*(x_)^2), x_Symbol] :> Dist[(2*c*d - b*e)/(2*c), Int[1/(a +
 b*x + c*x^2), x], x] + Dist[e/(2*c), Int[(b + 2*c*x)/(a + b*x + c*x^2), x], x] /; FreeQ[{a, b, c, d, e}, x] &
& NeQ[2*c*d - b*e, 0] && NeQ[b^2 - 4*a*c, 0] &&  !NiceSqrtQ[b^2 - 4*a*c]

Rule 1671

Int[(Pq_)*((a_) + (b_.)*(x_) + (c_.)*(x_)^2)^(p_.), x_Symbol] :> Int[ExpandIntegrand[Pq*(a + b*x + c*x^2)^p, x
], x] /; FreeQ[{a, b, c}, x] && PolyQ[Pq, x] && IGtQ[p, -2]

Rubi steps \begin{align*} \text {integral}& = \int \left (1-\frac {x}{1+x+x^2}\right ) \, dx \\ & = x-\int \frac {x}{1+x+x^2} \, dx \\ & = x+\frac {1}{2} \int \frac {1}{1+x+x^2} \, dx-\frac {1}{2} \int \frac {1+2 x}{1+x+x^2} \, dx \\ & = x-\frac {1}{2} \log \left (1+x+x^2\right )-\text {Subst}\left (\int \frac {1}{-3-x^2} \, dx,x,1+2 x\right ) \\ & = x+\frac {\tan ^{-1}\left (\frac {1+2 x}{\sqrt {3}}\right )}{\sqrt {3}}-\frac {1}{2} \log \left (1+x+x^2\right ) \\ \end{align*}

Mathematica [A] (verified)

Time = 0.01 (sec) , antiderivative size = 31, normalized size of antiderivative = 1.00 \[ \int \frac {1+x^2}{1+x+x^2} \, dx=x+\frac {\arctan \left (\frac {1+2 x}{\sqrt {3}}\right )}{\sqrt {3}}-\frac {1}{2} \log \left (1+x+x^2\right ) \]

[In]

Integrate[(1 + x^2)/(1 + x + x^2),x]

[Out]

x + ArcTan[(1 + 2*x)/Sqrt[3]]/Sqrt[3] - Log[1 + x + x^2]/2

Maple [A] (verified)

Time = 0.76 (sec) , antiderivative size = 28, normalized size of antiderivative = 0.90

method result size
default \(x -\frac {\ln \left (x^{2}+x +1\right )}{2}+\frac {\arctan \left (\frac {\left (1+2 x \right ) \sqrt {3}}{3}\right ) \sqrt {3}}{3}\) \(28\)
risch \(x -\frac {\ln \left (4 x^{2}+4 x +4\right )}{2}+\frac {\arctan \left (\frac {\left (1+2 x \right ) \sqrt {3}}{3}\right ) \sqrt {3}}{3}\) \(32\)

[In]

int((x^2+1)/(x^2+x+1),x,method=_RETURNVERBOSE)

[Out]

x-1/2*ln(x^2+x+1)+1/3*arctan(1/3*(1+2*x)*3^(1/2))*3^(1/2)

Fricas [A] (verification not implemented)

none

Time = 0.30 (sec) , antiderivative size = 27, normalized size of antiderivative = 0.87 \[ \int \frac {1+x^2}{1+x+x^2} \, dx=\frac {1}{3} \, \sqrt {3} \arctan \left (\frac {1}{3} \, \sqrt {3} {\left (2 \, x + 1\right )}\right ) + x - \frac {1}{2} \, \log \left (x^{2} + x + 1\right ) \]

[In]

integrate((x^2+1)/(x^2+x+1),x, algorithm="fricas")

[Out]

1/3*sqrt(3)*arctan(1/3*sqrt(3)*(2*x + 1)) + x - 1/2*log(x^2 + x + 1)

Sympy [A] (verification not implemented)

Time = 0.05 (sec) , antiderivative size = 36, normalized size of antiderivative = 1.16 \[ \int \frac {1+x^2}{1+x+x^2} \, dx=x - \frac {\log {\left (x^{2} + x + 1 \right )}}{2} + \frac {\sqrt {3} \operatorname {atan}{\left (\frac {2 \sqrt {3} x}{3} + \frac {\sqrt {3}}{3} \right )}}{3} \]

[In]

integrate((x**2+1)/(x**2+x+1),x)

[Out]

x - log(x**2 + x + 1)/2 + sqrt(3)*atan(2*sqrt(3)*x/3 + sqrt(3)/3)/3

Maxima [A] (verification not implemented)

none

Time = 0.27 (sec) , antiderivative size = 27, normalized size of antiderivative = 0.87 \[ \int \frac {1+x^2}{1+x+x^2} \, dx=\frac {1}{3} \, \sqrt {3} \arctan \left (\frac {1}{3} \, \sqrt {3} {\left (2 \, x + 1\right )}\right ) + x - \frac {1}{2} \, \log \left (x^{2} + x + 1\right ) \]

[In]

integrate((x^2+1)/(x^2+x+1),x, algorithm="maxima")

[Out]

1/3*sqrt(3)*arctan(1/3*sqrt(3)*(2*x + 1)) + x - 1/2*log(x^2 + x + 1)

Giac [A] (verification not implemented)

none

Time = 0.27 (sec) , antiderivative size = 27, normalized size of antiderivative = 0.87 \[ \int \frac {1+x^2}{1+x+x^2} \, dx=\frac {1}{3} \, \sqrt {3} \arctan \left (\frac {1}{3} \, \sqrt {3} {\left (2 \, x + 1\right )}\right ) + x - \frac {1}{2} \, \log \left (x^{2} + x + 1\right ) \]

[In]

integrate((x^2+1)/(x^2+x+1),x, algorithm="giac")

[Out]

1/3*sqrt(3)*arctan(1/3*sqrt(3)*(2*x + 1)) + x - 1/2*log(x^2 + x + 1)

Mupad [B] (verification not implemented)

Time = 0.03 (sec) , antiderivative size = 29, normalized size of antiderivative = 0.94 \[ \int \frac {1+x^2}{1+x+x^2} \, dx=x-\frac {\ln \left (x^2+x+1\right )}{2}+\frac {\sqrt {3}\,\mathrm {atan}\left (\frac {2\,\sqrt {3}\,x}{3}+\frac {\sqrt {3}}{3}\right )}{3} \]

[In]

int((x^2 + 1)/(x + x^2 + 1),x)

[Out]

x - log(x + x^2 + 1)/2 + (3^(1/2)*atan((2*3^(1/2)*x)/3 + 3^(1/2)/3))/3